package com.example.tobisfirstapp;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MosaicActivity extends Activity {

	String path;
	Bitmap img;
	private boolean started = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		System.out.println("onCreate MosiacActivity");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mosaic);
		
	
		 path = getIntent().getStringExtra(SelectImageActivity.STATE_IMG_URL);
		
	     try {
	      img = BitmapFactory.decodeStream(getContentResolver().openInputStream(Uri.parse(path)));
	     } catch (FileNotFoundException e) {
	    	 System.out.println("Exception trying to fetch file in MosaicActivity");
	      // TODO Auto-generated catch block
	      e.printStackTrace();
	     }
	     
	     if(!started){
	    	 started = true;
	    	 this.mosaicy();
	     }
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.mosaic, menu);
		return true;
	}
	
	private void mosaicy(){
		Bitmap result = null;
		
		//read img from file system
		ArrayList<Bitmap> otherImgs = new ArrayList<Bitmap>();
		System.out.println("densitiy: "+img.getDensity());
		System.out.println("height: "+img.getHeight());
		System.out.println("width: "+img.getWidth());
		System.out.println("row bytes: "+img.getRowBytes());
		System.out.println("densitiy: "+img.getScaledWidth(img.getDensity()));
		
	
	//	System.out.println(Arrays.toString(pixels));
	
		//somehow cut img into pieces and iterate through the blocks
		//select a matching otherImg
		
	}
	
	@Override
	public void onSaveInstanceState(Bundle savedInstanceState){
    	
    	//savedInstanceState.putString(STATE_IMG_URL, imgPath);
    	
    	super.onSaveInstanceState(savedInstanceState);
    }

    public void onRestoreInstanceState(Bundle savedInstanceState){
        super.onRestoreInstanceState(savedInstanceState);
    }

}
